package com.example.demo.core.page;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Getter;
import org.springframework.data.domain.Page;

import java.util.List;

@Getter
public class PageResult<T> {

    private final List<T> list;

    private final long pages;

    private final long total;

    private PageResult(List<T> list, long pages, long total) {
        this.list = list;
        this.pages = pages;
        this.total = total;
    }

    public static <T> PageResult<T> ok(List<T> list, long pages, long total) {
        return new PageResult<>(list, pages, total);
    }

    public static <T> PageResult<T> ok(Page<T> page) {
        return new PageResult<>(page.getContent(), page.getTotalPages(), page.getTotalElements());
    }

    public static <T> PageResult<T> ok(IPage<T> page) {
        return new PageResult<>(page.getRecords(), page.getPages(), page.getTotal());
    }
}
